left
详情
主题:C语言 基础---char 循环赋值 返回 搜索

方法一:


#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <malloc.h>
#include <stdarg.h>


int main(void)
{
	char str[] = "abcdef";

	char* p = "str";

	int i = 0;
	for (; *p != '\0'; p++) {
		str[i] = *p;
		i++;
	}
	str[i] = '\0';

	printf("%s",str);
}

结果: str


方法二:

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <malloc.h>
#include <stdarg.h>


int main(void)
{
	char str[] = "abcdef";
	char* p = "str1";
	strcpy(str, p);
	printf("%s",str);
}

结果: str1
警告:
您是否确定删除贴子?
确定 取消
copyright